from enum import Enum, auto
from utils import LOG


class ContentType(Enum):
    # auto 用于为枚举类型自动赋值
    TEXT = auto()
    TABLE = auto()
    IMAGE = auto()


class Content:
    def __init__(self, content_type, original, translation=None):
        self.content_type = content_type    # 内容类型
        self.original = original            # 原始内容
        self.translation = translation      # 翻译内容
        self.status = False                 # 翻译状态

    def check_translation_type(self, translation):
        # isinstance 用于检查一个对象是否属于指定的类型
        if self.content_type == ContentType.TEXT and isinstance(translation, str):
            return True
        elif self.content_type == ContentType.TABLE and isinstance(translation, str):
            return True
        return False

    def set_translation(self, translation, status):
        if not self.check_translation_type(translation):
            raise ValueError(f"Invalid translation type. Expected {self.content_type}, but got {type(translation)}")
        self.translation = translation
        self.status = status